<?php
session_start();

if(!isset($_SESSION['id'])){
	header('Location:login.php');
}
if(isset($_POST['submit'])){
	$id=$_POST['id'];
	$licesneid=trim($_POST['licesneid']);
	//$beizhu=trim($_POST['beizhu']);
	$typeid=$_POST['typeid'];
	//print_r($_POST);die;
	if($licesneid==""){
		echo "<script>alert('机器码、备注不能为空！');history.go(-1);</script>";
	}elseif(!preg_match("/[\x{4e00}-\x{9fa5}A-Za-z0-9]{3,32}[,]{1}[\x{4e00}-\x{9fa5}A-Za-z.:0-9\n\r]{3,32}+$/u", $licesneid)){
		echo "<script>alert('机器码、备注由中文、英文、数字组成！');history.go(-1);</script>";
	}/*elseif(!preg_match("/^[\x{4e00}-\x{9fa5}A-Za-z,]+$/u", $beizhu)){
		echo "<script>alert('备注格式不正确');history.go(-1);</script>";
	}*/else{
		header("Content-Type:text/html;charset=utf-8");
		$connect=mysql_connect("localhost","root","");
		mysql_select_db("shenji",$connect);
		mysql_query("set names utf8");
		//得到当前用户
		session_start();
		$relusername=$_SESSION['username'];

		$lics = split("\r\n", $licesneid);
		//$beiz = explode("\r", $beizhu);
		$count = count($lics);
		for($i=0;$i<$count;$i++){
			$beiz=explode(",",$lics[$i]);
			if(!preg_match("/[\x{4e00}-\x{9fa5}A-Za-z0-9]{3,32}+$/u", $beiz[0])){
				echo "<script>alert('机器码由中文、英文、数字组成！');history.go(-1);</script>";
			}if(!preg_match("/[\x{4e00}-\x{9fa5}A-Za-z0-9.:]{3,32}+$/u", $beiz[1])){
				echo "<script>alert('备注由中文、英文、数字组成！');history.go(-1);</script>";
			}else{
				$sql="insert into jiekou(licesneid,beizhu,typeid) value('$beiz[0]','$beiz[1]','$typeid')";
				mysql_query($sql);
			}
			//print_r($beiz[0]);
			
		}

		echo "<script>alert('添加成功');location.href='select_jiekou.php';</script>";
	}
}






?>
